package com.hy.medicine.constant;


import com.hy.medicine.MedicineStockRecord;

/**
 * 库存工具类
 */
public class StockUtil {

    /**
     * 获取变动类型文本
     */
    public static String getChangeTypeText(Integer changeType) {
        if (changeType == null) return "未知";
        switch (changeType) {
            case StockConstant.CHANGE_TYPE_IN:
                return "入库";
            case StockConstant.CHANGE_TYPE_OUT:
                return "出库";
            case StockConstant.CHANGE_TYPE_ADJUST:
                return "调整";
            default:
                return "未知";
        }
    }

    /**
     * 格式化变动数量显示
     */
    public static String formatChangeQuantity(MedicineStockRecord record) {
        if (record == null || record.getChangeQuantity() == null) return "";

        if (record.getChangeType() == StockConstant.CHANGE_TYPE_IN) {
            return "+" + record.getChangeQuantity();
        } else if (record.getChangeType() == StockConstant.CHANGE_TYPE_OUT) {
            return "-" + Math.abs(record.getChangeQuantity());
        } else {
            return record.getChangeQuantity() > 0 ?
                   "+" + record.getChangeQuantity() :
                   String.valueOf(record.getChangeQuantity());
        }
    }
}
